// 云函数入口文件
const cloud = require('wx-server-sdk')

// 通过微信订阅 消息推送


cloud.init({
  // API 调用都保持和云函数当前所在环境一致
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数

exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.subscribeMessage.send({
        "touser": event.userId, // 通过 getWXContext 获取 OPENID,
        // "page": 'index',
        "lang": 'zh_CN',
        "data": {
          "thing1": {
            "value": event.userName+event.mg
          },
          "thing4": {
            "value": event.recruitName
          },
          "thing10": {
            "value": event.result
          },
          "thing7": {
            "value": event.tips
          },
        },
        "templateId": 'sy27sJ0XfFqR1yWmU0wOZ5hEZVe3RmvRREUAA00Yc80',
        "miniprogramState": 'developer'
      })
    return result
  } catch (err) {
    return err
  }
}
